package com.elink.enginerring.user.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

import com.elink.enginerring.user.dao.UserMapper;
import com.elink.enginerring.user.dao.UserRoleMapper;
import com.elink.enginerring.user.entity.User;
import com.elink.enginerring.user.entity.UserRole;

@Service
public class UserService implements IUserService {
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private UserRoleMapper  userRoleMapper;

	/**
	 * 登录
	 */
	@Override
	public User getUserByNameAndPwd(String phone, String pwd) {
		pwd = DigestUtils.md5DigestAsHex(pwd.getBytes());
		User user = userMapper.selectByNameAndPwd(phone, pwd);
		if (user != null) {
			return user;
		} else {
			return null;
		}
	}

	@Override
	public void updateSysUserPw(String userId, String md5DigestAsHex) {
		userMapper.updatePw(userId,md5DigestAsHex);
	}

	@Override
	public List<UserRole> selectRole(String userId) {
		return userRoleMapper.selectRole(userId);
	}
}